Skip to content

Serve the whole body for a suffix range longer than it - #2615

Merged
yhirose merged 1 commit into
yhirose:masterfrom
youdie006:range-suffix-longer-than-body
Oct 8, 2026
Merged

yhirose merged 1 commit into
yhirose:masterfrom
youdie006:range-suffix-longer-than-body

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

A suffix range longer than the body is answered with 416:

Range on a 7-byte body master this PR Go net/http
bytes=-7 206, bytes 0-6/7 206, bytes 0-6/7 206, bytes 0-6/7
bytes=-8, bytes=-9999 416 206, bytes 0-6/7 206, bytes 0-6/7
bytes=-0 416 416

RFC 9110 §14.1.2: "If the selected representation is shorter than the specified suffix-length, the entire representation is used." In range_error, first_pos = content_len - last_pos goes negative and fails the validity check below it. #711 clamped this at 0; the clamp was lost when fceada9 reworked range handling, and GetStreamedWithRangeSuffix2 was changed to expect 416. #2009 restored the other half of the same paragraph (a last-byte-pos past the end means the remainder); this does the same for the suffix form. coalesce_ranges has the same arithmetic, but it only sees ranges range_error has already normalized.

GetStreamedWithRangeSuffix2 now expects the whole body for bytes=-8 and bytes=-9999, and the 416 assertions move to GetStreamedWithRangeSuffixZero with bytes=-0. Clamping at 1 instead of 0, or not at all, fails the new expectations. With g++ and the Makefile's flags (ASan, no TLS), *Range* (43) and ServerTest.* (188) pass and clang-format --dry-run --Werror is clean; I did not run the TLS builds or the full CI matrix.

Written with AI assistance (Claude); I have reviewed the change.

RFC 9110 14.1.2: if the representation is shorter than the suffix-length,
the entire representation is used. range_error computed a negative first
byte position for bytes=-8 on a 7-byte body and answered 416. Clamp it
at 0, as yhirose#711 did before the range handling was reworked.
@yhirose
yhirose merged commit 2130296 into yhirose:master Oct 8, 2026
28 checks passed
@yhirose

yhirose commented Oct 8, 2026

Copy link
Copy Markdown
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants